package vn.com.vega.music.view.adapter;

import java.util.ArrayList;

import vn.com.vega.chacha.R;
import vn.com.vega.music.objects.Package;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListPackageAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private ArrayList<Package> mPackageList;

	public ListPackageAdapter(ArrayList<Package> list, Context ctx) {
		mInflater = LayoutInflater.from(ctx);
		mPackageList = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mPackageList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mPackageList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.view_listview_row_context_menu, null);
			holder = new ViewHolder();
			holder.image = (ImageView) convertView
					.findViewById(R.id.common_context_menu_row_thumbnail_img);
			holder.arrow = (ImageView) convertView
					.findViewById(R.id.common_context_menu_row_arrow_img);
			holder.first_text = (TextView) convertView
					.findViewById(R.id.common_context_menu_row_first_txt);
			holder.second_text = (TextView) convertView
					.findViewById(R.id.common_context_menu_row_second_txt);
			holder.image.setVisibility(ImageView.VISIBLE);
			// holder.image.setBackgroundResource(R.drawable.ic_package);
			holder.arrow.setVisibility(ImageView.VISIBLE);
			// holder.arrow.setBackgroundResource(R.drawable.ic_listview_arrow);
			holder.second_text.setVisibility(TextView.VISIBLE);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Package currPackage = (Package) getItem(position);
		holder.first_text.setText(currPackage.name);
		holder.second_text.setText(currPackage.price);

		return convertView;
	}

	class ViewHolder {
		TextView first_text;
		TextView second_text;
		ImageView image;
		ImageView arrow;

	}

}
